package gate.controller.config;

import base.correspond.CorrespondBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常统一处理
 */
@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalControllerExceptionConfig {
    @ExceptionHandler(value = Exception.class)
    public CorrespondBean globalExceptionCatch(Exception ex) {
        log.error("[Tao 's words] : "+ex.toString());
        if (ex.getMessage().equals("IllegalToken")) {
            return CorrespondBean.getFailBean("msg","IllegalToken!请重新登录！");
        } else {
            return CorrespondBean.getFailBean("msg","程序出现错误，请联系管理员");
        }

    }
}
